All Questions
17 questions
1vote
1answer
524views
Cheapest flights within k stops algorithm in JavaScript
The problem: There are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is ...
-3votes
1answer
815views
HackerRank | Roads and Libraries - Code Optimization
Major Edit: I wish people threw in a comment regarding what they are expecting instead of downvoting this question. I am quite appreciative of constructive feedback. I know it is only 3 people out of ...
-2votes
1answer
149views
How to work in linear time with DFS
I tried a Hackerrank problem and it gives me a successful message, it works fine for Hackerrank criteria. The member states of the UN are planning to send 2 people to the moon. They want them to be ...
6votes
1answer
183views
City Construction Solution times out for large input
Problem The country of Hackerland has n cities connected by m uni-directional roads. The cities are numbered from ...
1vote
0answers
304views
Graph-coloring solution using depth-first search
I'm trying to solve this question: Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them. The park consists of n squares ...
7votes
1answer
932views
Hackerrank: Computer Game (max-flow problem with integer factorization)
I am working on a coding challenge from the Hackerrank site. Given two equal-length arrays of integers, with values from 2 to 109, find the maximum number of times we can remove a pair (Ai, Bj) where ...
7votes
2answers
218views
Heights of Cats
I have an assignment to solve this problem. However, I have exceeded the time limit required, can anyone suggest where to improve my code? Cats like to sit in high places. It is not uncommon to see ...
1vote
2answers
583views
Determine whether a node is reachable
I am working on this HackerRank problem but running into time constraint issues. Basically, given two arrays, we need to determine if the ith element of the second array is reachable by the ith ...
6votes
1answer
181views
Finding intersting path in a graph
There is a question in a contest but it doesn't have any answer. I solve it but I get time limit for most of test case. Is it possible to improve my code or give a better approach? Question There is ...
7votes
1answer
795views
Cheapest flights with at most k stops
This is the Cheapest Flights Within K Stops problem from leetcode.com: There are \$n\$ cities connected by \$m\$ flights. Each fight starts from city \$u\$ and arrives at \$v\$ with a price \$w\$. ...
3votes
0answers
122views
SPOJ Fast Matching challenge
I wrote a solution to the MATCHING challenge on SPOJ: FJ has N (1 ≤ N ≤ 50,000) cows and M (1 ≤ M ≤ 50,000) bulls. Given a list of P (1 ≤ P ≤ 150,000) potential matches between a cow and a bull, ...
5votes
1answer
329views
AIO programming challenge - Friendlist - Who has the most friends?
I attempted this sample question from the Australia Infomatics Competition. TL;DR - Each line of input contains two numbers, representing a mutual friendship relationship. The output needs to be the ...
3votes
2answers
2kviews
Dijkstra's algorithm in JavaScript
I'm trying to implement Dijkstra's algorithm to find the shortest path. This is from a challenge on CodeWars. In this scenario there is a map: ...
4votes
1answer
1kviews
Finding the max cost from the minimum cost incurred on travelling
This problem is from INOI 2014 , where I have find out the maximum cost of traveling through the cities but taking the minimum possible route cost , here is an excerpt from it, Indian National ...
5votes
2answers
2kviews
My attempt at Dijkstra's Algorithm in Python 3
I am practicing my coding at HackerRank. The exact problem statement can be found here, but to summarize, it is finding the distances of the shortest path from a starting node to every other node in a ...